sr=48000
kr=4800
nchnls=2


    instr 1 
  kmask     linuxjoystick   0, 1
;;; this uses the first two axes on your joystick.
  kaxes     tab       0, 1
  kdbg      tab       kaxes+11, 1
  kf0       tab       kaxes+6, 1
  kf1       tab       kaxes+7, 1
  kf2       tab       kaxes+8, 1
  kf3       tab       kaxes+9, 1
  kx        tab       2, 1
  ky        tab       3, 1
  kx2       tab       4, 1
  ky2       tab       5, 1
  k_r1, ktheta1       cart2polar                  kx, ky
  k_rdiff1, kangdiff1 rotation                    kx, ky
  k_r2, ktheta2       cart2polar                  kx2, ky2
  k_rdiff2, kangdiff2 rotation                    kx2, ky2

  icps      =  (44100/sr)/(2/3)
  imaxovr   =  10000
  iphsdiv   =  2*$M_PI
  kfmr      =  6.08768E-06
  kdurfac   =  13770.3
  kmindur   =  0.0236984
  kdens     =  1.77953
  kmindens  =  0.944882
  kpmdr     =  1
  kfrpow    =  -1.81102
  kprpow    =  1.77953


;   kfmr      ctrl7     1, 1, 0, (1/3)/32767
;   kdurfac   ctrl7     1, 2, 65528, 4096
;   kmindur   ctrl7     1, 12, 0.0001, 0.1
;   kdens     ctrl7     1, 3, 1, 100
;   kmindens  ctrl7     1, 13, 0, 20
;   kpmdr     ctrl7     1, 4, 0.01, 1
;   kfrpow    ctrl7     1, 6, -2, 2
;   kprpow    ctrl7     1, 7, -2, 2
; printf "kfmr %G\\nkdurfac %G\\nkmindur %G\\nkdens %G\\nkmindens %G\\nkpmdr %G\\nkfrpow %G\\nkprpow %G\\n\\n", kdbg, kfmr, kdurfac, kmindur, kdens, kmindens, kpmdr, kfrpow, kprpow

  kfmd      =  (32767-k_r1)*kfmr
  kdur      =  (k_r2/kdurfac)+kmindur
  kpmd      =  (kangdiff1/iphsdiv)*kpmdr
  kdens     =  (kangdiff2/(2*$M_PI)+$M_PI)*kdens+kmindens
  kcps      =  icps+(k_rdiff1/32767)

  iwfn      =  4
  kfn1       =  2
  kfn2       =  3
  kphs1      =  (ktheta1+$M_PI)/iphsdiv
  kphs2      =  (ktheta2+$M_PI)/iphsdiv
  agl        grain3    kcps, kphs1, kfmd, kpmd, kdur, kdens, imaxovr, kfn1, iwfn, kfrpow, kprpow  
  agr        grain3    kcps, kphs2, kfmd, kpmd, kdur, kdens, imaxovr, kfn2, iwfn, kfrpow, kprpow  
  iampscale =  65/32767
            outs      agl*ampdb(k_r1*iampscale), agr*ampdb(k_r2*iampscale)
    endin
